package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;

import cn.sumpu.app.guoguojie.dao.LeaveMessageDao;
import cn.sumpu.app.guoguojie.domain.LeaveMessage;
import cn.sumpu.app.guoguojie.domain.Ext.LeaveMessageExt;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class LeaveMessageDaoImpl extends SqlSessionDaoSupport implements
		LeaveMessageDao {

	@Override
	public void insert(LeaveMessage leaveMessage) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("cn.sumpu.app.guoguojie.persistence.LeaveMessageMapper.insert",
							leaveMessage);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Write database failure.", e);
			}
			throw new AppBusinessException("Write database failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	public List<LeaveMessageExt> getLeaveMessageList(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return getSqlSession()
					.selectList(
							"cn.sumpu.app.guoguojie.persistence.LeaveMessageMapper.getLeaveMessageList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("query database failure.", e);
			}
			throw new AppBusinessException("query database failure.", e);
		}
	}

	@Override
	public void delete(String id) throws AppBusinessException {
		try {
			getSqlSession()
					.delete("cn.sumpu.app.guoguojie.persistence.LeaveMessageMapper.deleteLeaveMessageById",
							id);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("delete failure.", e);
			}
			throw new AppBusinessException("delete failure.", e);
		}

	}

}
